package com.example.leetdemo.process;

import java.util.ArrayList;

public class Solution1813 {

    public boolean areSentencesSimilar(String sentence1, String sentence2) {
        String[] l1 = sentence1.length() > sentence2.length() ? sentence1.split(" ") : sentence2.split(" ");
        String[] l2 = sentence1.length() <= sentence2.length() ? sentence1.split(" ") : sentence2.split(" ");
        int i = 0, j = 1;
        while (i + j <= l2.length) {
            boolean t1 = true, t2 = true;
            if (l1[i].equals(l2[i])) {
                i++;
            } else {
                t1 = false;
            }
            if (l1[l1.length - j].equals(l2[l2.length - j])) {
                j++;
            } else {
                t2 = false;
            }
            if (!t1 && !t2) {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        Solution1813 solution1813 = new Solution1813();
        System.err.println(solution1813.areSentencesSimilar("of", "A lot of words"));

        ArrayList<String> list;
    }
}
